package net.daum.enocoin.xmleditor;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextInputListener;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.editors.text.TextEditor;

public class XMLEditor extends TextEditor {

	private ColorManager colorManager;

	public XMLEditor() {
		super();
		colorManager = new ColorManager();
		setSourceViewerConfiguration(new XMLConfiguration(colorManager));
		setDocumentProvider(new XMLDocumentProvider());

	}

	public void dispose() {
		colorManager.dispose();
		super.dispose();

	}

	@Override
	public void createPartControl(Composite parent) {
		super.createPartControl(parent);
		this.addListener();
	}

	public void addListener() {

		ISourceViewer a = getSourceViewer();
		if (a == null)
			System.out.println("source viewer is null");
		else {
			System.out.println("source view is not null");
			getSourceViewer().addTextInputListener(textInputListener);
			getSourceViewer().getTextWidget().addKeyListener(keyListener);
		}
	}

	KeyListener keyListener = new KeyListener() {

		public void keyPressed(KeyEvent e) {
			System.out.println(e);
		}

		public void keyReleased(KeyEvent e) {
			System.out.println("re " + e);
		}
	};

	ITextInputListener textInputListener = new ITextInputListener() {
		public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
			System.out.println("inputDocumentAboutToBeChanged 진입");
			if (oldInput != null)
				System.out.println("about " + oldInput.get());
			if (newInput != null)
				System.out.println("about " + newInput.get());

		}

		public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
			System.out.println("inputDocumentChanged 진입");
			if (oldInput != null)
				System.out.println(oldInput.get());
			if (newInput != null)
				System.out.println(newInput.get());
		}
	};
}
